package com.ruanhb.wsp.controller;

import com.ruanhb.wsp.service.DataClient;
import com.ruanhb.wsp.service.WeatherReportService;
import com.ruanhb.wsp.vo.City;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by r on 2018-9-21
 */
@Slf4j
@Controller
@RequestMapping("report")
public class WeatherReportController {

    @Autowired
    private WeatherReportService weatherReportService;

    @Autowired
    private DataClient dataClient;

    @GetMapping("/cityId/{cityId}")
    public ModelAndView getReportByCityId(@PathVariable("cityId") String cityId ,
                                          Model model) throws Exception {
        model.addAttribute("title","坑爹的天气预报");
        model.addAttribute("cityId",cityId);
        model.addAttribute("cityList",dataClient.cityList());
        model.addAttribute("report",weatherReportService.getWeatherDataByCityId(cityId));
        return new ModelAndView("weather/report","reportModel",model);
    }
}
